/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.commons;

import com.android1.amarena2d.engine.EngineObject;
import com.badlogic.gdx.math.Vector2;

import java.util.Random;

public class Tools extends EngineObject {

    public static final Random RANDOM = new Random(System.nanoTime());
    public static final float PI = 3.14159265358979323846F;

    public static void setToCenter(Vector2 vector) {
        vector.set(engine.getCamera().getWidth() / 2, engine.getCamera().getHeight() / 2);

    }

    public static boolean isZero(Vector2 pos) {
        return (!(pos.x != 0.0F || pos.y != 0.0F));
    }

    /// returns a random float between -1 and 1
    public static float randomMinus1To1() {
        return RANDOM.nextFloat() * 2.0f - 1.0f;
    }

    public static float random0To1() {
        return RANDOM.nextFloat();
    }

    public static float degreesToRadians(float angle) {
        return (angle / 180.0f * PI);
    }

    public static float radiansToDegrees(float angle) {
        return (angle / PI * 180.0f);
    }

    public static boolean isPowerOfTwo(final int n) {
        return ((n != 0) && (n & (n - 1)) == 0);
    }

    public static int nextPowerOfTwo(final int n) {
        int k = n;

        if (k == 0) {
            return 1;
        }

        k--;

        for (int i = 1; i < 32; i <<= 1) {
            k = k | k >> i;
        }

        return k + 1;
    }

}
